package com.nciae.converter;

import com.google.gson.Gson;
import com.nciae.dto.OrderDTO;
import com.nciae.form.OrderForm;
import com.nciae.po.OrderDetail;

import java.util.ArrayList;

public class OrderForm2OrderDTOConverter {

    public static OrderDTO convert(OrderForm orderForm) {

        Gson gson = new Gson();
        OrderDTO orderDTO = new OrderDTO();

        orderDTO.setBuyerName(orderForm.getName());
        orderDTO.setBuyerPhone(orderForm.getPhone());
        orderDTO.setBuyerAddress(orderForm.getAddress());
        orderDTO.setBuyerOpenid(orderForm.getOpenid());

        ArrayList<OrderDetail> orderDetailList = new ArrayList<>();
        orderDTO.setOrderDetailList(orderForm.getItems());

//        try {
//            gson.fromJson(orderForm.getItems(),
//                    new TypeToken<List<OrderDetail>>(){}.getType()
//            );
//        }catch (Exception e) {
//            throw new SellException(ResultEnum.PARAM_ERROR);
//        }

        return orderDTO;

    }

}